import React from 'react'
import {useDispatch,useSelector} from "react-redux"
import {useEffect} from "react"
import axios from 'axios'
import Myclass from './myclass'
import * as action from "../action"
// import {bindActionCreators} from "redux" // 合并抽离出去的action 的
// useSelector是获取仓库数据的
// usedispatch是触发dispacth的
function App() {
   const dispatch = useDispatch()
   const store = useSelector((state)=>{
       return {
           ...state.appreducer
       }
   })
   useEffect(()=>{
       dispatch(action.getlist())
   },[])
   console.log(store);
   const setname = (data)=> {
       // 除了type必须叫type，其他的这个对象中想加什么字段加什么字段
    //    dispatch({
    //        type:"setname1",
    //        payload:data
    //    })
       dispatch(action.setname())
      
   }
  return (
    <div>app
        <Myclass></Myclass>
        <hr />
        <p>我是仓库的数据 {store.name}
            <button onClick={()=>setname("zhaoliu")}>点击我修改name</button>
            {
                store.arr && store.arr.length? store.arr.map((item,index)=>{
                    return <div key={index}><span>{item.Name}</span><img src={item.CoverPhoto} alt="" /></div>
                }):"暂无数据"
            }
        
        </p>
    </div>
  )
}

export default App